Skip to content

fix(firestore): generate unique listener IDs on web#989

Open
robingenz wants to merge 2 commits into
mainfrom
feat/issue-986
Open

fix(firestore): generate unique listener IDs on web#989
robingenz wants to merge 2 commits into
mainfrom
feat/issue-986

Conversation

@robingenz
Copy link
Copy Markdown
Member

Summary

  • Replaces Date.now().toString() listener ID generation in FirebaseFirestoreWeb with a per-instance incrementing counter, so multiple snapshot listeners registered in the same millisecond no longer collide and overwrite each other in unsubscribesMap (the earlier listeners then couldn't be removed).
  • Applies the same fix to FirebaseStorageWeb, where downloadFile and uploadFile returned non-unique callback IDs for the same reason.

Test plan

  • Register two snapshot listeners back-to-back on the same document/collection on web; confirm both receive callbacks and both can be individually removed via removeSnapshotListener.
  • Change the document data after removing the first listener; confirm only the still-active listener fires.
  • npm run build for both packages succeeds.

Closes #986

robingenz added 2 commits May 25, 2026 10:32
Listener IDs were derived from `Date.now()`, so listeners created in the
same millisecond shared an ID and overwrote each other in the
unsubscribes map, leaving the earlier ones unable to be removed.

Replace the timestamp with a per-instance incrementing counter. The same
issue was present in the storage plugin (downloadFile/uploadFile
callback IDs) and is fixed here as well.

Closes #986
Copilot AI review requested due to automatic review settings May 25, 2026 08:35
@robingenz robingenz self-assigned this May 25, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a web-side listener/callback ID collision issue by replacing Date.now().toString() with per-instance incrementing counters, preventing overwrites when multiple listeners/callbacks are created within the same millisecond (addressing #986).

Changes:

  • Firestore (web): generate unique snapshot listener IDs via an incrementing counter and store them in unsubscribesMap.
  • Storage (web): generate unique callback IDs for downloadFile / uploadFile via an incrementing counter.
  • Add a changeset bumping both @capacitor-firebase/firestore and @capacitor-firebase/storage as patch releases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/storage/src/web.ts Replaces time-based callback IDs with per-instance incrementing IDs for web download/upload callbacks.
packages/firestore/src/web.ts Replaces time-based listener IDs with per-instance incrementing IDs to avoid unsubscribesMap collisions.
.changeset/firestore-storage-unique-listener-ids.md Adds a patch changeset documenting the fix for both packages.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 25, 2026

Open in StackBlitz

@capacitor-firebase/analytics

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/analytics@989

@capacitor-firebase/app

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/app@989

@capacitor-firebase/app-check

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/app-check@989

@capacitor-firebase/authentication

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/authentication@989

@capacitor-firebase/crashlytics

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/crashlytics@989

@capacitor-firebase/firestore

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/firestore@989

@capacitor-firebase/functions

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/functions@989

@capacitor-firebase/messaging

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/messaging@989

@capacitor-firebase/performance

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/performance@989

@capacitor-firebase/remote-config

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/remote-config@989

@capacitor-firebase/storage

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/storage@989

commit: 3857021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(firestore): web unable to unsubscribe some listeners

2 participants